package operation.duoxianliu.demo07;

import java.util.ArrayList;
import java.util.Random;

public class Lottery implements Runnable {
    private int[] arr = {10, 5, 20, 50, 100, 200, 500, 800, 2, 80, 300, 700};
    ArrayList<Integer> list = new ArrayList<>();
    Random r = new Random();

    @Override
    public void run() {
        int a = 0;
        while (true) {
            synchronized (this) {
                String name = Thread.currentThread().getName();
                if (list.size() == arr.length) {
                    System.out.println(name + "总共抽取了" + a + "次");
                    break;
                }
                int index = r.nextInt(arr.length);
                if (!list.contains(arr[index])) {
                    list.add(arr[index]);
                    System.out.println("抽奖箱" + name + "又产生了一个" + arr[index] + "元大奖");
                    a++;
                }
            }
        }
    }
}